package com.itheima.controller;

import com.itheima.domain.User;
import com.itheima.service.Impl.UserServiceImpl;
import com.itheima.service.UserService;
import org.junit.Test;

import java.util.*;

/**
 * 控制层
 */
public class UserTest {
    UserService service = new UserServiceImpl();

    @Test
    public void login() {
        //创建map集合
        Map<String, Object> map = new HashMap<String, Object>();
        //往集合中添加数据
        map.put("username", "秃三炮");
        map.put("password", "930077");
        //调用业务层方法
        User user = service.login(map);
        System.out.println("user = " + user);
    }

    @Test
    public void findUserNameAndPasswordById() {
        //定义id
        Integer id = 27;
        //调用业务层方法
        Map map = service.findUserNameAndPasswordById(id);
        System.out.println("map = " + map);
    }
    @Test
    public void findMapByMap() {
        //创建list集合,装map集合
        List<Map> list = new ArrayList<Map>();
        Map parameterMap = new HashMap();
        Map resultMap = new HashMap();
        //往参数集合中添加数据
        parameterMap.put("id1",17);
        parameterMap.put("id2",27);
        //调用业务层方法
        list = service.findMapByMap(parameterMap);
        for (Map map : list) {
          resultMap.put(map.get("username"),map.get("password"));
        }
        System.out.println("resultMap = " + resultMap);
    }
    @Test
    public void findByNameAndPassword() {
       User user=service.findByNameAndPassword("黄金标",444);
        System.out.println("user = " + user);
    }
    @Test
    public void findByIds() {
        //创建list集合
        List<Integer> idList = new ArrayList<Integer>();
        idList.add(27);
        idList.add(17);
        List<User> list=service.findByIds(idList);
        for (User user : list) {
            System.out.println("user = " + user);
        }
    }
}
